﻿
$(function() {
    CreateMCE();
    prm.add_endRequest(
    function(sender, args) {
        $('textarea:tinymce').tinymce().setContent("");
        CreateMCE();
    });

});

function GetTinyMceEditor(textboxId) {
    return tinyMCE.get(textboxId);
}

function myCustomCleanup(type, value) {
    if (type == "insert_to_ed tor") {
        value = value.replace(/&lt;/gi, "<");
        value = value.replace(/&gt;/gi, ">");
    }
    return value;
}

function myCustomSaveContent(element_id, html, body) {
    html = html.replace(/</gi, "&lt;");
    html = html.replace(/>/gi, "&gt;");
    return html;
}

function CreateMCE() {


    $('textarea.advanced-editor').tinymce
    ({
        script_url: relRootPath + '/Scripts/tiny_mce/tiny_mce.js',
        theme: "advanced",
        plugins: "safari,pagebreak,layer,table,advhr,advimage,advlink,emotions,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
        theme_advanced_toolbar_location: "top",
        theme_advanced_toolbar_align: "left",
        theme_advanced_resizing: false,
        language: "ii",
        theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,fontselect,fontsizeselect,|,image,code,preview,fullscreen",
        theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,cleanup,|,insertdate,inserttime,|,forecolor,backcolor",
        theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,cite,del,|,blockquote,pagebreak",
        content_css: relRootPath + '/Content/mce/content.css?' + new Date().getTime(),
        cleanup_callback: "myCustomCleanup",
        entity_encoding: "named",
        invalid_elements: "script,style"
    });


    $('textarea.simple-editor').tinymce
        ({
            script_url: relRootPath + '/Scripts/tiny_mce/tiny_mce.js',
            theme: "advanced",
            plugins: "safari,pagebreak,style,layer,table,advhr,advimage,advlink,emotions,inlinepopups,iespell,insertdatetime,preview,searchreplace,print,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
            theme_advanced_toolbar_location: "top",
            theme_advanced_toolbar_align: "left",
            theme_advanced_resizing: false,
            language: "ii",
            content_css: relRootPath + '/Content/mce/content.css?' + new Date().getTime(),
            theme_advanced_buttons1: "bold,italic,underline,|,link,unlink,|,image,emotions,|,forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,|,cleanup,|,fullscreen",
            theme_advanced_buttons2: "",
            theme_advanced_buttons3: "",
            nowrap: false,
            cleanup_callback: "myCustomCleanup",
            entity_encoding: "named",
            invalid_elements: "script,style"
        });

        $('textarea.comment-editor').tinymce
        ({
            script_url: relRootPath + '/Scripts/tiny_mce/tiny_mce.js',
            theme: "advanced",
            plugins: "safari,style,emotions,iespell,inlinepopups,preview,searchreplace,template",
            theme_advanced_toolbar_location: "top",
            theme_advanced_toolbar_align: "left",
            theme_advanced_resizing: false,
            language: "ii",
            content_css: relRootPath + '/Content/mce/content.css?' + new Date().getTime(),
            theme_advanced_buttons1: "bold,italic,underline,|,emotions,|,forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,|,cleanup",
            theme_advanced_buttons2: "",
            theme_advanced_buttons3: "",
            nowrap: false,
            cleanup_callback: "myCustomCleanup",
            entity_encoding: "named",
            invalid_elements: "script,style"
        });
}